package com.glowdayz.glowmee.bc;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.glowdayz.common.DBHandler;
import com.glowdayz.glowmee.cmd.PouchProductMapCMD;
import com.glowdayz.glowmee.dao.BrandDAO;
import com.glowdayz.glowmee.dao.PouchProductMapDAO;
import com.glowdayz.glowmee.dao.RegisterDAO;

public class MappingProductBC extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
    
    public MappingProductBC() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		DBHandler.getInstance().connect();
		
		request.setCharacterEncoding("utf-8");
		
		int id = Integer.parseInt(request.getParameter("id"));
		
		try {
			PouchProductMapCMD cmd = PouchProductMapDAO.getInstance().getMappingProduct(id);
			
			if (cmd.getNickName() == null) {
				int idRegister = cmd.getIdRegister();
				String name = RegisterDAO.getInstance().getRegisterNickName(idRegister);
				cmd.setNickName(name);
			}
			
			if (cmd.getImage() != null) {
				request.setAttribute("image", cmd.getImage());
			}
			request.setAttribute("cmd", cmd);
			request.setAttribute("brand", BrandDAO.getInstance().getBrandList(1, -1, "brandTitle", "b.isDisplay=1"));
		} catch (Exception e) {
			DBHandler.getInstance().disconnect();
			e.printStackTrace();
		}
		
		DBHandler.getInstance().disconnect();
		RequestDispatcher dpr = request.getRequestDispatcher("/product/mappingProduct.jsp");
		dpr.forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}
	
}
